#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2018/11/19 23:52
@desc
"""

from bs4 import BeautifulSoup
import requests

rep = requests.get("http://sh.fang.com/")
rep.encoding = "gb18030"
print(rep.apparent_encoding)
html = rep.text
soup = BeautifulSoup(html, 'html.parser')
# 获取顶层 新盘推荐 的整个div
div = soup.find('div', attrs={'id': 'ti011'})
# 获取四个楼盘的div，更具他们的class = "tenrtd"
for house in div.find_all('div', attrs={'class': 'tenrtd'}):
    # 根据class="text1"获取存储楼盘标题的div
    titleDiv = house.find('div', attrs={'class': 'text1'})
    title = titleDiv.find('a').text
    # 根据class="text2"获取存储楼盘价格的div
    priceDiv = house.find('div', attrs={'class': 'text2'})
    price = priceDiv.find('b').text
    print(title + " " + price)
